Sure! Below is an example of how to implement a simple CAPTCHA in Laravel 8. We'll use the popular Google reCAPTCHA service to add CAPTCHA functionality to a form in a Laravel application.
```bash
composer create-project laravel/laravel laravel-captcha-demo
cd laravel-captcha-demo
```
```bash
composer require anhskohbo/no-captcha
```
```php
```
```php
```
```dotenv
NOCAPTCHA_SECRET=your-secret-key
NOCAPTCHA_SITEKEY=your-site-key
```
Create a new form that includes the reCAPTCHA widget. For this example, let's create a contact form.
```php
// routes/web.php
use Illuminate\Support\Facades\Route;
return view('contact');
});
$request->validate([
'name' => 'required|string',
'email' => 'required|email',
'message' => 'required|string',
'g-recaptcha-response' => 'required|captcha',
]);
// Process the contact form data and send an email, etc.
return redirect('/contact')->with('success', 'Message sent successfully!');
});
```
```html
@if (session('success'))
@endif
```
```bash
php artisan serve
```
That's it! You now have a CAPTCHA-enabled form in your Laravel 8 application, protecting it from automated bots and spam submissions.